#include <iostream>
#include <algorithm>
#include <cstdio>
#include <array>
using namespace std;
#ifdef ONLINE_JUDGE

/* #define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++) */
/* char buf[1 << 23], *p1 = buf, *p2 = buf, ubuf[1 << 23], *u = ubuf; */

#endif
int read() {
    int p = 0, flg = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') flg = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        p = p * 10 + c - '0';
        c = getchar();
    }
    return p * flg;
}
void write(int x) {
    if (x < 0) {
        x = -x;
        putchar('-');
    }
    if (x > 9) {
        write(x / 10);
    }
    putchar(x % 10 + '0');
}
bool _stmer;

const int N = 1e6 + 5;

char strbuf[N];
array <int, N> f;

bool _edmer;
int main() {
    cerr << (&_stmer - &_edmer) / 1024.0 / 1024.0 << "MB\n";
#ifndef cxqghzj
    freopen("good.in", "r", stdin);
    freopen("good.out", "w", stdout);
#endif
    int n = read(), q = read();
    scanf("%s", strbuf);
    string s = strbuf; s = " " + s;
    int _ans = 0;
    while (q--) {
        int l = read(), r = read(), res0 = 0, res1 = 0;
        for (int i = l; i <= r; i++) {
            if (s[i] == '0') res0++;
            else res1++;
            f[i] = f[i - 1];
            if (res0 > res1) f[i] = max(f[i], res0 - res1);
        }
        res0 = 0, res1 = 0;
        int ans = f[r];
        for (int i = r; i >= l; i--) {
            if (s[i] == '0') res0++;
            else res1++;
            if (f[i] < f[i + 1]) res1 += f[i + 1] - f[i];
            if (res0 > res1) ans += res0 - res1, res0 = res1;
        }
        for (int i = l; i <= r; i++) f[i] = 0;
        _ans ^= ans;
    }
    write(_ans), puts("");
    return 0;
}
